package com.cskaoyan;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class Main {

    public static void main(String[] args) throws IOException {

        // 1. 获取sqlSessionFactoryBuilder
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();

        // 2. 获取sqlSessionFactory
//        InputStream inputStream = Main.class.getClassLoader().getResourceAsStream("mybatis-config.xml");
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");

        SqlSessionFactory sqlSessionFactory = builder.build(inputStream);


        // 3. 获取sqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession();

        // 4. 执行sql语句
        Object object = sqlSession.selectOne("cskaoyan.selectAccountById", 2);

        System.out.println(object);


        // 5. 关闭sqlSession
        sqlSession.close();

    }
}
